package com.fjp.heartguard.ui.report.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.fjp.heartguard.R
import com.fjp.heartguard.app.data.bean.ReportsItem
import com.fjp.heartguard.app.ext.setAdapterAnimation
import com.fjp.heartguard.app.util.SettingUtil


class ReportAdapter(data: ArrayList<ReportsItem>, var clickItem: (item: ReportsItem,index:Int) -> Unit) : BaseQuickAdapter<ReportsItem, BaseViewHolder>(R.layout.item_report, data) {
    init {
        setAdapterAnimation(SettingUtil.getListMode())
    }

    override fun convert(holder: BaseViewHolder, item: ReportsItem) {
        holder.setText(R.id.nameTv, item.name+"（ID: ${item.older_id}）")
        holder.setText(R.id.timeTv, item.created_at)
        holder.setText(R.id.sexValueTv, item.sex)
        holder.setText(R.id.ageValueTv, item.age.toString())
        holder.setText(R.id.addressValueTv, item.address)
        holder.setText(R.id.questionValueTv, item.title)
        if (item.sex == "男") {
            holder.setBackgroundResource(R.id.avatarIv, R.drawable.avatarman)
        } else {
            holder.setBackgroundResource(R.id.avatarIv, R.drawable.avatar_woman)
        }

        holder.itemView.setOnClickListener {
            clickItem(item,holder.bindingAdapterPosition)
        }
    }

}


